<template>
	<view class="content">
		<view class="title">
			支付方式
		</view>
		<view class="item" v-for="(item,index) in list" :key="index" @tap="changeItem(item)">
			<view class="left">
				<image :src="item.img" class="imgs"></image>
				<view>{{item.title}}</view>
			</view>
			<image :src="selectId == item.id?'../../static/payWay/select.png':'../../static/payWay/noSelect.png'" class="selectIcon"></image>
		</view>
		
		<view class="submit" @tap="submit">确认支付</view>
	</view>
</template>

<script>
	import { buyGoods,buyVoucherGoods,rushToBuy } from '../../api/api.js'
	export default {
		data() {
			return {
				selectId:1,
				list:[
					{id:1,title:'多多券支付',img:'../../static/payWay/balance.png'},
					// {id:2,title:'微信',img:'../../static/payWay/wx.png'},
					// {id:3,title:'支付宝',img:'../../static/payWay/zfb.png'}
				],
				goodsId:'',
				quantity:'',
				receiver:'',
				receiverPhone:'',
				province:'',
				city:'',
				county:'',
				detailAddress:'',
				isVoucher:''  // 是否是多多券商品
			}
		},
		onLoad(e) {
			this.goodsId = e.goodsId
			this.quantity = e.quantity
			// this.receiver = e.receiver
			// this.receiverPhone = e.receiverPhone
			// this.province = e.province
			// this.city = e.city
			// this.county = e.county
			// this.detailAddress = e.detailAddress
			// this.isVoucher = e.isVoucher
		},
		methods: {
			changeItem(item) {
				this.selectId = item.id
			},
			
			submit() {
				let data = {
					goodsId:this.goodsId,
					quantity:this.quantity
				}
				rushToBuy(data).then( res=> {
					if( res.code == 200 ) {
						uni.showToast({
							title:'购买成功，请在我的订单中查看',
							icon:'none'
						})
						setTimeout(function() {
							uni.navigateBack({
								delta:1
							})
						},500)
					}
				})
				// let data = {
				// 	goodsId:this.goodsId,
				// 	quantity:this.quantity,
				// 	receiver:this.receiver,
				// 	receiverPhone:this.receiverPhone,
				// 	province:this.province,
				// 	city:this.city,
				// 	county:this.county,
				// 	detailAddress:this.detailAddress,
				// }
				// if( this.isVoucher == 1 ) {
				// 	buyVoucherGoods(data).then( res=> {
				// 		if( res.code == 200 ) {
				// 			uni.showToast({
				// 				title:'购买成功，请在我的订单中查看',
				// 				icon:'none'
				// 			})
				// 			setTimeout(function() {
				// 				uni.navigateBack({
				// 					delta:1
				// 				})
				// 			},500)
				// 		}
				// 	})
				// }else {
				// 	buyGoods(data).then( res=> {
				// 		if( res.code == 200 ) {
				// 			uni.showToast({
				// 				title:'购买成功，请在我的订单中查看',
				// 				icon:'none'
				// 			})
				// 			setTimeout(function() {
				// 				uni.navigateBack({
				// 					delta:1
				// 				})
				// 			},500)
				// 		}
				// 	})
				// }
			}
		}
	}
</script>

<style lang="less" scoped>
  .content {
	  .title {
		  margin-bottom: 30rpx;
		  padding-left: 30rpx;
		  height: 99rpx;
		  font-size: 32rpx;
		  font-family: PingFangSC-Medium, PingFang SC;
		  font-weight: 500;
		  color: #1A1A1A;
		  line-height: 99rpx;
		  width: 720rpx;
		  border: 1rpx solid rgba(238, 238, 238, 1);
	  }
	  .item {
		  margin-bottom: 40rpx;
		  padding: 0 30rpx;
		  width: 690rpx;
		  display: flex;
		  align-items: center;
		  justify-content: space-between;
		  .left {
			  font-size: 28rpx;
			  font-family: PingFangSC-Regular, PingFang SC;
			  font-weight: 400;
			  color: #1A1A1A;
			  line-height: 40rpx;
			  display: flex;
			  align-items: center;
			  .imgs {
				  margin-right: 24rpx;
				  width: 44rpx;
				  height: 44rpx;
			  }
		  }
		  .selectIcon {
			  width: 36rpx;
			  height: 36rpx;
		  }
	  }
	  .submit {
		  position: fixed;
		  left: 30rpx;
		  bottom: 33rpx;
		  text-align: center;
		  line-height: 90rpx;
		  width: 690rpx;
		  height: 90rpx;
		  background: #FE3B33;
		  border-radius: 4rpx;
		  font-size: 30rpx;
		  font-family: PingFangSC-Medium, PingFang SC;
		  font-weight: 500;
		  color: #FFFFFF;
	  }
  }
</style>
